package com.cloudcentral.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisIndexedHttpSession;
import org.springframework.session.security.SpringSessionBackedSessionRegistry;

/**
 * Create by Administrator
 * 2023/11/10 9:28
 */
@Configuration
@EnableRedisIndexedHttpSession
public class SpringSessionBackedSessionRegistryConfig {
  private final FindByIndexNameSessionRepository<? extends Session> sessionRepository;

  @Autowired
  public SpringSessionBackedSessionRegistryConfig(FindByIndexNameSessionRepository<? extends Session> sessionRepository) {
    this.sessionRepository = sessionRepository;
  }

  @Bean
  public SessionRegistry sessionRegistry() {
    return new SpringSessionBackedSessionRegistry<>(sessionRepository);
  }
}
